/**
 * created by guyi 2018.01.19
 */
'use strict';
var express = require('express');
var router = express.Router();
var Post = require('../models/Post');
var superagent = require('superagent');

var jwt = require('jsonwebtoken');
var redis = require("redis");
var yzmService = require("../routes/yzmService");
var client = redis.createClient(6379, "127.0.0.1");
var UserService = require('../services/UserService');
const PostService = require('../services/PostService');
var moment = require('moment')

async function send(req, res, next) {
    var {nickname, content, imgUrl, phone} = req.body;
    // req.body.createdAt = moment().format('YYYY-MM-DD HH:mm:ss');
    var PostEntity = new Post(req.body);
    // PostEntity.save((err, doc) => {
    //     if (err) {
    //         console.log("ERROR:"+err);
    //     }
    //     res.send('post success')
    // });
    res.send(await PostEntity.save());

}

async function getOnePost (req,  res, next) {
    var post = await Post.findById(req.query.id);
    if (post) {
        res.send(post);
    }
}

async function getAllPost (req, res, next) {
    var time = req.query.time;
    
}


module.exports = {send, getOnePost}